package com.cardone.platform.authority.service;

import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.springframework.transaction.annotation.Transactional;

import com.cardone.common.dto.PaginationDto;
import com.cardone.context.ContextHolder;
import com.cardone.platform.authority.dao.PermissionDao;
import com.cardone.platform.authority.dto.PermissionDto;
import com.google.common.collect.Lists;

/**
 * 许可服务
 *
 * @author yaohaitao
 *
 */
@Getter
@Setter
@Transactional(readOnly = true)
public class PermissionDefaultService implements PermissionService {
	@Override
	@Transactional
	public int deleteByIds(final PermissionDto deletePermission) {
		return ContextHolder.getBean(PermissionDao.class).deleteByIds(deletePermission);
	}

	@Override
	public <P> P findByCodeOrId(final Class<P> mappedClass, final PermissionDto findPermission) {
		return ContextHolder.getBean(PermissionDao.class).findByCodeOrId(mappedClass, findPermission);
	}

	@Override
	public <P> P findById(final Class<P> mappedClass, final PermissionDto findPermission) {
		return ContextHolder.getBean(PermissionDao.class).findById(mappedClass, findPermission);
	}

	@Override
	public <P> List<P> findListByLikeCode(final Class<P> mappedClass, final PermissionDto findListPermission) {
		return ContextHolder.getBean(PermissionDao.class).findListByLikeCode(mappedClass, findListPermission);
	}

	@Override
	public <P> List<P> findListBySiteId(final Class<P> mappedClass, final String siteId) {
		return ContextHolder.getBean(PermissionDao.class).findListBySiteId(mappedClass, siteId);
	}

	@Override
	public <P> List<P> findListBySiteIdAndRoleId(final Class<P> mappedClass, final String siteId, final String roleId) {
		return ContextHolder.getBean(PermissionService.class).findListBySiteIdAndRoleIdList(mappedClass, siteId, Lists.newArrayList(roleId));
	}

	@Override
	public <P> List<P> findListBySiteIdAndRoleIdList(final Class<P> mappedClass, final String siteId, final List<String> roleIdList) {
		return ContextHolder.getBean(PermissionDao.class).findListBySiteIdAndRoleIdList(mappedClass, siteId, roleIdList);
	}

	@Override
	public <P> List<P> findListBySiteIdAndTypeCode(final Class<P> mappedClass, final String siteId, final String typeCode) {
		return ContextHolder.getBean(PermissionDao.class).findListBySiteIdAndTypeCode(mappedClass, siteId, typeCode);
	}

	@Override
	public <P> List<P> findListBySiteIdAndTypeId(final Class<P> mappedClass, final String siteId, final String typeId) {
		return ContextHolder.getBean(PermissionDao.class).findListBySiteIdAndTypeId(mappedClass, siteId, typeId);
	}

	@Override
	@Transactional
	public int insertByCode(final PermissionDto insertPermission) {
		return ContextHolder.getBean(PermissionDao.class).insertByCode(insertPermission);
	}

	@Override
	public <P> PaginationDto<P> paginationByLikeCode(final Class<P> mappedClass, final PermissionDto paginationPermission) {
		return ContextHolder.getBean(PermissionDao.class).paginationByLikeCode(mappedClass, paginationPermission);
	}

	@Override
	public Integer readByCodeNqIdForCount(final PermissionDto readPermission) {
		return ContextHolder.getBean(PermissionDao.class).readByCodeNqIdForCount(readPermission);
	}

	@Override
	public List<String> readCodeListBySiteIdAndTypeCode(final String siteId, final String typeCode) {
		return ContextHolder.getBean(PermissionDao.class).readCodeListBySiteIdAndTypeCode(siteId, typeCode);
	}

	@Override
	@Transactional
	public <P> P saveByIdOrCode(final Class<P> mappedClass, final PermissionDto savePermission) {
		return ContextHolder.getBean(PermissionDao.class).saveByIdOrCode(mappedClass, savePermission);
	}

	@Override
	@Transactional
	public int updateByCode(final PermissionDto updatePermission) {
		return ContextHolder.getBean(PermissionDao.class).updateByCode(updatePermission);
	}
}